package com.walleipt.corgi.api.controller;

import java.util.Map;

import org.mangoframework.core.annotation.Get;
import org.mangoframework.core.annotation.RequestMapping;
import org.mangoframework.core.annotation.RequestParam;

import com.walleipt.corgi.api.annotations.Ignore;
import com.walleipt.corgi.api.ex._HashMap;
import com.walleipt.corgi.api.utils.HttpUtils;

/**
 * 通过小程序login的code获取session_key和openId
 * @author user
 *
 */
@RequestMapping("/getXcxSessionInfo")
public class GetXcxSessionInfoController {

	private String appId = "wxd5f7e3a5e16e3ee6" ;
	
	
	private String _url = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=7dbfd96bf94ed610d198cd10c13c747a&js_code=%s&grant_type=authorization_code" ;
	
	@Ignore // 调过login
	@Get("/{code}")
	public Object getSessionKeyAndOpenId(@RequestParam("code")String code) {
		Map<String,Object> result = HttpUtils.getJSON( String.format(_url,appId.trim(), code.trim()) ) ;
        return new _HashMap<>( result );
    }
}
